﻿Imports Oracle.DataAccess.Client
Public Class fListaTipoGastos
    Dim lidTipoGasto As String
    Public ReadOnly Property idTipoGasto() As String
        Get
            Return lidTipoGasto
        End Get
    End Property
    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        If Me.txtTipoGasto.Text.Trim.Length > 0 Then
            cmd.CommandText = "SELECT IDGASTO, DESCRIPCION FROM CAJ_TIPOGASTO WHERE DESCRIPCION LIKE '" & Me.txtTipoGasto.Text & "'"
        Else
            cmd.CommandText = "SELECT IDGASTO, DESCRIPCION FROM CAJ_TIPOGASTO "
        End If

        Try
            Conn.Open()
            DsCaja.CAJ_TIPOGASTO.Clear()
            DsCaja.CAJ_TIPOGASTO.Load(cmd.ExecuteReader)
            Conn.Close()
            CAR_TIPOGASTODataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub


    Private Sub CAR_TIPOGASTODataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles CAR_TIPOGASTODataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lidTipoGasto = CAR_TIPOGASTODataGridView.Rows(e.RowIndex).Cells("IDGASTO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub AsignaTipoGasto(ByVal Fila As Integer)
        If Fila >= 0 Then
            lidTipoGasto = CAR_TIPOGASTODataGridView.Rows(Fila).Cells("IDGASTO").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub CAR_TIPOGASTODataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles CAR_TIPOGASTODataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaTipoGasto(CAR_TIPOGASTODataGridView.CurrentRow.Index)
        End If
    End Sub
End Class